# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def getIntersectionNode(self, headA: ListNode, headB: ListNode) -> ListNode:
        if headA is None or headB is None:
            return None
        dic = set()
        tmp = headA
        while tmp:
            dic.add(tmp)
            tmp = tmp.next
        tmp = headB
        while tmp:
            if tmp in dic:
                return tmp
            tmp = tmp.next

        return None

if __name__ == '__main__':
    so = Solution()
    s = [1,1,1,3]
    r = so.findMin(s)
    print(r)
